beta<-read.table("merged_beta.txt",sep="\t",head=T,colClasses=c("character",rep("numeric",2661)),stringsAsFactors =F,na.strings=c('-'))
sitenames<-c("BREAST","COLON","GLIOBLASTOMA","KIDNEY RENAL CLEAR","KIDNEY RENAL PAPILLARY","BLOOD LEUKEMIA","LUNG ADENOMA","LUNG SQUAMOUS","OVARY","RECTUM","STOMACH","UTERUS")
#
data<-c()
col<-c()
i<-1
while(i<=length(table(a1[,1])))
{
	print(i)
	print(names(table(a1[,1]))[i])
	temp<-c()
	temp<-a1[which(a1[,1]==names(table(a1[,1]))[i]),]
	k<-1
	m<-length(table(temp[,7]))
	if(m>3)
	{
		m<-3
	}
	while(k<=m)
	{
		min<-5
		if(min > length(which(temp[,7]==as.character(names(table(temp[,7]))[k]))))
		{
			min<-length(which(temp[,7]==as.character(names(table(temp[,7]))[k])))
		}
		#print(min)
		temp1<-temp[which(temp[,7]==as.character(names(table(temp[,7]))[k]))[1:min],]
		data<-rbind(data,temp1)
		col<-c(col,rep(k+1,min))
		k<-k+1
	}
	i<-i+1
}
j<-1
temp1<-c()
while(j<=nrow(data))
{
	temp1[j]<-paste(data[j,],collapse='.')
	j<-j+1
}
temp<-c()
temp<-beta[,temp1]
rownames(temp)<-beta[,1]
main<-paste('Tissue',names(table(a1[,1]))[i],sitenames[i],sep='-')
if(length(table(col))>7)
{
	col[which(col==9)]<-4
}
site<-data[,1]
site[which(site=="BRCA")]<-1
site[which(site=="COAD")]<-2
site[which(site=="GBM")]<-3
site[which(site=="KIRC")]<-4
site[which(site=="KIRP")]<-5
site[which(site=="LAML")]<-6
site[which(site=="LUAD")]<-7
site[which(site=="LUSC")]<-8
site[which(site=="OV")]<-9
site[which(site=="READ")]<-10
site[which(site=="STAD")]<-11
site[which(site=="UCEC")]<-12
pdf("interbatch.pdf",width=15, height=8)
boxplot(temp,horizontal=FALSE,show.names = TRUE,xlab="SAMPLES",ylab="Beta",ylim=c(0,1),col=col,names=site)
legend("top",cex=0.4,title="Tissue",c("1:BREAST","2:COLON","3:GLIOBLASTOMA","4:KIDNEY RENAL CLEAR","5:KIDNEY RENAL PAPILLARY","6:BLOOD LEUKEMIA","7:LUNG ADENOMA","8:LUNG SQUAMOUS","9:OVARY","10:RECTUM","11:STOMACH","12:UTERUS"),horiz=T)
dev.off()	



	



	
	